<?php
/**
 * 教室信息类
 */
namespace app\admin\controller;

use think\App;
use think\facade\View;
use app\admin\model\Tagsmodel;
use app\admin\model\Classroom;
use app\admin\validate\Content as validate;

class Tags extends Common
{
    protected $croommodel;

    public function __construct(App $app)
    {
        $this->validate = validate::class;
        $this->validateType = 'tags';
        $this->localModel = new Tagsmodel();
        parent::__construct($app);
        $this->croommodel = new Classroom();
    }

    public function index()
    {
        $where = $showDataArr = [];

        $dataArr = $this->request->request('search/a', []);

        if($dataArr['title'])   $where[] = ['t.title', 'like', "%".$dataArr['title']."%"];
        if($dataArr['cid'])     $where[] = ['cid', '=', $dataArr['cid']];
        if($dataArr['status'])  $where[] = ['t.status', '=', $dataArr['status']];
        if(session('adminUserInfo.cid'))  $where[] = ['cid', 'in', session('adminUserInfo.cid').', 0'];

        $list = $this->localModel->findAll($where, $this->request->param());
        $showDataArr = ['infoData'=>$list['data'], 'pageData'=>$list['page'], 'dataArr'=>$dataArr];
        View::assign($showDataArr);
        return view();
    }

    public function add(){
        $id  = $this->request->get('id', 0);

        $croomData = $this->croommodel->findAllInfo('id, name', [['status', '=', 1]]);

        $showData = ['croomData'=>$croomData];
        $showData['fid'] = $this->request->get('fid', 0);
        if($showData['fid']){
            $fdetail = $this->localModel->findDetaiInfoById('cid', $showData['fid']);
            $showData['cid'] = $fdetail['cid'];
        }
        if($id){
            $showData['id'] = $id;
            $showData['detail'] = $this->localModel->findDetaiInfoById('*', $id);
            View::assign($showData);
            return view('edit');
        }else{
            View::assign($showData);
            return view();
        }
    }

}
